package com.lucky.blog.controller;

import com.lucky.system.domain.MenuDO;
import com.lucky.system.domain.TagDO;
import com.lucky.system.service.MenuService;
import com.lucky.system.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;


/**
 * blog路由
 */
@Controller
@RequestMapping("/blog")
public class BlogController {

	@Autowired
	MenuService menuService;

	@Autowired
	TagService tagService;

	@GetMapping()
	String blog() {
		return "blog/index/main";
	}

	@GetMapping("/detail")
	String nes(@RequestParam long cid, Model model) {
		model.addAttribute("cid",cid);
		return "blog/index/nes";
	}

	@GetMapping("/{data}/list/{id}")  //article || tag
	String article(Model model, @PathVariable String data,@PathVariable long id) {
		String titleName = null;
		if(data.equals("article")){
			MenuDO menu = menuService.get(id);
			titleName = menu.getName();
		}else {
			TagDO tagDO = tagService.get((int) id);
			titleName = tagDO.getTagName();
		}
		model.addAttribute("id",id);
		model.addAttribute("type",data);
		model.addAttribute("titleName",titleName);
		return "blog/index/list";
	}
}
